/**
 * 会议详情
 * @author Qasim <15750783791@163.com>
 * @version 2016/9/5
 */
var self = phone = id = uid = tid =  '';

document.addEventListener('plusready' , ready ,  false);

function ready(){
	 
	self = plus.webview.currentWebview();
	
	var memberInfo = plus.storage.getItem('memberInfo');
	
	memberInfo = $.parseJSON(memberInfo);
	
	uid = memberInfo.aid;
	
	$('.title').text(self.title);
	 
	$('.bbs-inf-text').html(self.body.indexOf('src="http') >= 0 ? self.body : self.body.replace(/src="/g , 'src="' + webRoot))
	 
	id = self.aid; 
	 
	tid = self.tid;
	
 	//浏览量与收藏状态
 	plus.nativeUI.showWaiting('加载中...');
 	
 	$.ajax({  
 		
		type:"post", 
		
		url:apiRoot + '/Home/Article/collection_status/',
		
		data:{
			uid : uid , 
			aid : id ,
			tid : tid,
			evaluate : 'evaluate'
		},
		
		dataType : 'json',
		
		success : function(data){ 
			
			plus.nativeUI.closeWaiting();  
			
			if(data.status)$('.collection_status').css('color' , 'darkgoldenrod');
			
			$('.hits').text(data.hits);
			
		},
		error : function(e){
			console.log(JSON.stringify(e))
			toast('连接超时,请检查网络');
			plus.nativeUI.closeWaiting();
		}
		
	});
 	
 	//收藏
 	$('.collection').on('click' , function(){
 		plus.nativeUI.showWaiting('操作中...'); 
 		$.ajax({  
 			type:"post", 
 			url:apiRoot + '/Home/Article/collection/',
 			data:{
 				uid : uid , 
 				aid : id ,
 				tid : tid
 			},
 			success : function(data){ 
 				plus.nativeUI.closeWaiting();  
 				var type = '';
 				if(data == 0){ 
 					toast('已取消');
 					type = '取消收藏';
 					$('.collection_status').css('color' , 'aliceblue');
 				}else{
 					toast('已收藏');
   					$('.collection_status').css('color' , 'darkgoldenrod');
 				}
 				
   				if(self.page){
   					mui.fire(plus.webview.getWebviewById(self.page) , 'cancel' ,{
	 					id : id  ,
	 					type : type
					});
   				}
 			},
 			error : function(e){
 				console.log(JSON.stringify(e))
 				toast('连接超时,请检查网络');
 				plus.nativeUI.closeWaiting();
 			}
 			
 		});
 	})
 	
// 	点击分享
	$('.share').each(function(index) { 
		var type = ex = content = ''  
		$(this).on('click', function() {
			if(index == 0) {type = 'weixin' ; ex = 'WXSceneSession'; content = '';} 
			if(index == 1) {type = 'qq' ; ex = ''; content = $('.content').text() ; } 
			if(index == 2) {type = 'weixin' ; ex = 'WXSceneTimeline';content = '';}
			shareAction(type, ex , id , '端砚生物' , '' , '' , uid , tid);
		})
	})
 	
}
